package cn.panda.edu.controller;

import cn.panda.edu.model.CourseInform;
import cn.panda.edu.service.CourseInformService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * 类描述： 课程通知的控制层 
 * @author: 陈飞帆  
 * @date： 2018-01-17 下午3:48:34
 */
@RestController
@RequestMapping("/api/teacher/courseInform")
public class TeacherCourseInformController {
	@Autowired
	private CourseInformService courseInformService;
	
	
	@ApiOperation(value = "分页获取课程通知", notes = "") // 用以指明API名称
	@ApiImplicitParam(name = "pageIndex", value = "当前页数", required = true, dataType = "Integer")
	@RequestMapping(value = "/getlist", method = RequestMethod.POST)
	public Object getAllExam(Integer pageIndex) {
		if(pageIndex==null) {
			pageIndex=1;
		}

		PageInfo<CourseInform> pageInfo = courseInformService.getAllInform(pageIndex,Constant.PAGE_SIZE);
		return ResultDataUtil.resData(200, "", pageInfo);
	}

	@ApiOperation(value = "根据id删除课程通知", notes = "")
	@ApiImplicitParam(name = "id", value = "课程通知id", required = true, dataType = "Integer")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public  Object deleteByPrimaryKey(Integer id) {
		int status=200;
		String message=null;
		try {
			courseInformService.deleteByPrimaryKey(id);
			status=200;
			message="删除成功！";
		} catch (Exception e) {
			status=500;
			message="删除失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}

	@ApiOperation(value = "发布课程通知", notes = "")
	@ApiImplicitParam(name = "courseInform", value = "课程通知实体类", required =false, dataType = "CourseInform",paramType="form")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public Object insert(CourseInform courseInform) {
		int status=200;
		String message=null; 
		try {
			courseInformService.insertSelective(courseInform);
			status=200;
			message="添加成功！";
		} catch (Exception e) {
			status=500;
			message="添加失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	
}
